﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CustomGUIToggleGroup : MonoBehaviour
{
    private CustomGUIToggle[] toggles;
    private CustomGUIToggle fontTurTog;
    void Start()
    {
        toggles = this.GetComponentsInChildren<CustomGUIToggle>();
        if (toggles.Length == 0)
            return;
        for (int i=0; i<toggles.Length; i++)
        {
            CustomGUIToggle toggle = toggles[i];
            toggle.changeValue += (value) =>
            {
                if (value)
                {
                    for (int j = 0; j < toggles.Length; j++)
                    {
                        if (toggles[j] != toggle)
                        {
                            toggles[j].isSel = false;
                        }
                    }
                    fontTurTog = toggle;
                }
                else if(toggle == fontTurTog)
                {
                    toggle.isSel = true;
                }
            };
        }
    }
}
